package com.borened.netty.protocol.mqtt;

import io.netty.buffer.ByteBuf;

public class MqttUtils {

    public static String readString(ByteBuf buf) {
        int length = buf.readUnsignedByte();
        byte[] data = new byte[length];
        for (int i = 0; i < length; i++) {
            data[i] = buf.readByte();
        }
        return new String(data);
    }

    public static boolean readBoolean(ByteBuf buf) {
        return buf.readByte() == 1;
    }

    public static int readUint16(ByteBuf buf) {
        return buf.readUnsignedShort();
    }
}